package net.skyedu.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import net.skyedu.bean.BasGrade;
import net.skyedu.bean.BasSchool;
import net.skyedu.bean.BasSubject;
import net.skyedu.bean.BasTerm;

/**
 * 实报课表
 * @author Jason
 *
 * date 2013-1-31
 */
public class DaoSupport extends DAO{
	
	private Connection conn = null;
	private PreparedStatement pstmt = null;
	private ResultSet rs = null;
	
	/**
	 * show all school
	 * @return 
	 */
	public List<BasSchool> searchSchool(){
		List<BasSchool> list = new ArrayList<BasSchool>();
		BasSchool bs = null;
		StringBuffer sql = new StringBuffer("select DeptId,DeptName from Edu_Department where DeptId not in (7,10,15) and IsBranch=1");
		try{
			conn = this.getConn();
			pstmt = conn.prepareStatement(sql.toString());
			rs = pstmt.executeQuery();
			while(rs.next()){
				bs = new BasSchool();
				bs.setSchId(rs.getInt("DeptId"));
				bs.setSchName(rs.getString("DeptName"));
				list.add(bs);
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			this.closeAll(conn, pstmt, rs);
		}
		return list;
	}
	/**
	 * show all term
	 * @return
	 */
	public List<BasTerm> searchTerm(){
		List<BasTerm> list = new ArrayList<BasTerm>();
		BasTerm bs = null;
		StringBuffer sql = new StringBuffer("select * from Edu_Period where PeriodId>32 order by PeriodId desc");
		try{
			conn=this.getConn();
			pstmt=conn.prepareStatement(sql.toString());
			rs=pstmt.executeQuery();
			while(rs.next()){
				bs=new BasTerm();
				bs.setTerId(rs.getInt("PeriodId"));
				bs.setTerName(rs.getString("PeriodName"));
				bs.setPeriodYear(rs.getString("PeriodYear"));
				list.add(bs);
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			this.closeAll(conn, pstmt, rs);
		}
		return list;
	}
	/**
	 * @return
	 */
	public List<BasGrade> searchGrade(){
		List<BasGrade> list =new ArrayList<BasGrade>();
		BasGrade bs=null;
		StringBuffer sql=new StringBuffer("select * from Edu_Grade");
		try{
			conn=this.getConn();
			pstmt=conn.prepareStatement(sql.toString());
			rs=pstmt.executeQuery();
			while(rs.next()){
				bs=new BasGrade();
				bs.setGraId(rs.getInt("GradeId"));
				bs.setGraName(rs.getString("GradeName"));
				list.add(bs);
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			this.closeAll(conn, pstmt, rs);
		}
		return list;
	}
	/**
	 * show all subject
	 * @return 
	 */
	public List<BasSubject> searchSubject(){
		List<BasSubject> list =new ArrayList<BasSubject>();
		BasSubject bs=null;
		StringBuffer sql=new StringBuffer("select * from Edu_Subject order by SubjectId");
		try{
			conn=this.getConn();
			pstmt=conn.prepareStatement(sql.toString());
			rs=pstmt.executeQuery();
			while(rs.next()){
				bs=new BasSubject();
				bs.setSubId(rs.getInt("SubjectId"));
				bs.setSubName(rs.getString("SubjectName"));
				list.add(bs);
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			this.closeAll(conn, pstmt, rs);
		}
		return list;
	}
	
}
